```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>缓存系统设计指南 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
            background-color: #f9fafb;
        }
        .hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .section-title {
            position: relative;
            padding-bottom: 1rem;
            margin-bottom: 2rem;
        }
        .section-title:after {
            content: "";
            position: absolute;
            bottom: 0;
            left: 0;
            width: 60px;
            height: 4px;
            background: linear-gradient(90deg, #667eea, #764ba2);
            border-radius: 2px;
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
            border-radius: 8px;
            overflow: hidden;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .strategy-card {
            border-left: 4px solid #667eea;
        }
        .tooltip-icon {
            cursor: pointer;
            color: #667eea;
            margin-left: 0.25rem;
        }
        .pros-cons-item {
            position: relative;
            padding-left: 1.5rem;
        }
        .pros-cons-item:before {
            content: "";
            position: absolute;
            left: 0;
            top: 0.6em;
            width: 0.75rem;
            height: 0.75rem;
            border-radius: 50%;
        }
        .pros:before {
            background-color: #10b981;
        }
        .cons:before {
            background-color: #ef4444;
        }
        .footer-line {
            position: relative;
            padding-top: 1.5rem;
        }
        .footer-line:before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 1px;
            background: linear-gradient(90deg, rgba(255,255,255,0.1), rgba(255,255,255,0.5), rgba(255,255,255,0.1));
        }
        .mermaid {
            background-color: white;
            padding: 1.5rem;
            border-radius: 0.5rem;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4">
        <div class="container mx-auto max-w-6xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">缓存系统设计指南</h1>
                    <p class="text-xl opacity-90 mb-8">构建高性能、高可用的分布式缓存系统</p>
                    <div class="flex flex-wrap gap-4">
                        <div class="bg-white bg-opacity-20 px-4 py-2 rounded-full flex items-center">
                            <i class="fas fa-bolt mr-2"></i>
                            <span>高性能</span>
                        </div>
                        <div class="bg-white bg-opacity-20 px-4 py-2 rounded-full flex items-center">
                            <i class="fas fa-shield-alt mr-2"></i>
                            <span>高可用</span>
                        </div>
                        <div class="bg-white bg-opacity-20 px-4 py-2 rounded-full flex items-center">
                            <i class="fas fa-expand-arrows-alt mr-2"></i>
                            <span>可扩展</span>
                        </div>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="mermaid w-full max-w-md">
                        graph TD
                            A[客户端] --> B[缓存层]
                            B --> C{缓存命中?}
                            C -->|是| D[返回缓存数据]
                            C -->|否| E[数据库]
                            E --> F[返回数据]
                            F --> G[更新缓存]
                            G --> D
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-6xl py-12 px-4">
        <!-- Introduction Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">项目中缓存的设计</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="mb-6 text-lg">随着系统访问量和数据规模的增大，缓存不仅能大幅度减少数据库或后端服务的负载，还能极大提升请求的响应速度，让用户获得更为流畅的使用体验。</p>
                    <p class="mb-6">然而，缓存并不是简单地在系统中增加一层数据读取的中间层而已。要真正发挥缓存的作用并避免常见问题如缓存雪崩、缓存击穿和缓存穿透，就需要在设计阶段深入理解缓存的作用机制和潜在的挑战。</p>
                </div>
                <div class="bg-white p-6 rounded-lg shadow-md card">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1730173676904-e371121f-ce9e-43c4-85f0-3fbd82ecb5f8.png" alt="缓存架构图" class="w-full rounded">
                </div>
            </div>
            <div class="mt-8 bg-blue-50 p-6 rounded-lg">
                <h3 class="text-xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-lightbulb text-blue-500 mr-2"></i>
                    关键设计考虑
                </h3>
                <ul class="grid md:grid-cols-2 gap-4">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                        <span>数据的读写频率和更新策略</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                        <span>缓存的生命周期和失效机制</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                        <span>热数据保护和访问峰值管理</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                        <span>多层级设计与数据库协同</span>
                    </li>
                </ul>
            </div>
        </section>

        <!-- Cache Strategies Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">缓存策略选择</h2>
            <p class="text-lg mb-8">在项目中进行缓存设计时，缓存策略的选择至关重要，它直接影响系统的性能和缓存的有效性。一个好的缓存策略不仅能够显著提升请求的响应速度，还能降低对数据库或后端服务的依赖，减轻负载压力。</p>
            
            <div class="mb-8">
                <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1730173722167-7f3eb155-d584-4547-b065-0e38236f46f8.png" alt="缓存策略图" class="w-full rounded-lg shadow-md card">
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-6">1. 缓存策略的核心影响因素</h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-white p-6 rounded-lg shadow-sm strategy-card">
                        <h4 class="font-semibold text-lg mb-3">数据访问频率</h4>
                        <p>缓存策略的选择往往依赖于数据的访问频率。频繁访问的热点数据适合长时间缓存，而低频数据则可能适合短暂缓存或不缓存。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm strategy-card">
                        <h4 class="font-semibold text-lg mb-3">数据更新频率</h4>
                        <p>更新频繁的数据通常需要考虑较短的缓存时间，以保证数据的一致性。对更新不频繁的数据，则可以考虑较长的缓存时间。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm strategy-card">
                        <h4 class="font-semibold text-lg mb-3">数据的时效性</h4>
                        <p>不同的业务场景对数据的时效性要求不同。对于时效性要求较高的场景，需要更快地更新缓存。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm strategy-card">
                        <h4 class="font-semibold text-lg mb-3">系统资源情况</h4>
                        <p>如内存容量、存储成本和网络带宽等。高频访问的数据可以尽量选择放入内存缓存以提高速度，而冷数据可以考虑用外部存储缓存。</p>
                    </div>
                </div>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-6">2. 常见的缓存策略</h3>
                <div class="space-y-8">
                    <!-- LRU -->
                    <div class="bg-white p-6 rounded-lg shadow-sm card">
                        <h4 class="font-semibold text-xl mb-4 flex items-center">
                            <span class="bg-blue-100 text-blue-600 px-3 py-1 rounded-full text-sm mr-3">策略1</span>
                            LRU (Least Recently Used)
                            <i class="fas fa-info-circle tooltip-icon" title="最近最少使用策略会优先淘汰最近最少使用的数据"></i>
                        </h4>
                        <div class="grid md:grid-cols-2 gap-6">
                            <div>
                                <h5 class="font-medium mb-2">概念</h5>
                                <p>LRU策略会优先淘汰最近最少使用的数据，保留近期使用较频繁的数据。</p>
                            </div>
                            <div>
                                <h5 class="font-medium mb-2">适用场景</h5>
                                <p>适合存储容量有限且数据访问有较强的时间局部性的数据，如用户个人主页、推荐系统中的个性化推荐结果等。</p>
                            </div>
                        </div>
                        <div class="mt-4 grid md:grid-cols-2 gap-4">
                            <div>
                                <h5 class="font-medium mb-2">优点</h5>
                                <ul class="space-y-2">
                                    <li class="pros-cons-item pros">能很好地利用系统的局部性原理</li>
                                    <li class="pros-cons-item pros">实现相对简单高效</li>
                                    <li class="pros-cons-item pros">适合大多数常见访问模式</li>
                                </ul>
                            </div>
                            <div>
                                <h5 class="font-medium mb-2">缺点</h5>
                                <ul class="space-y-2">
                                    <li class="pros-cons-item cons">在更新频繁的数据中，可能导致不断的缓存替换</li>
                                    <li class="pros-cons-item cons">不适合周期性访问模式</li>
                                </ul>
                            </div>
                        </div>
                    </div>

                    <!-- LFU -->
                    <div class="bg-white p-6 rounded-lg shadow-sm card">
                        <h4 class="font-semibold text-xl mb-4 flex items-center">
                            <span class="bg-blue-100 text-blue-600 px-3 py-1 rounded-full text-sm mr-3">策略2</span>
                            LFU (Least Frequently Used)
                            <i class="fas fa-info-circle tooltip-icon" title="最少使用策略会根据数据的访问频次淘汰访问次数最少的数据"></i>
                        </h4>
                        <div class="grid md:grid-cols-2 gap-6">
                            <div>
                                <h5 class="font-medium mb-2">概念</h5>
                                <p>LFU策略会根据数据的访问频次淘汰访问次数最少的数据。</p>
                            </div>
                            <div>
                                <h5 class="font-medium mb-2">适用场景</h5>
                                <p>适合那些访问频率较为稳定的系统，例如新闻系统的热门新闻缓存，能确保高频访问的数据留存更长时间。</p>
                            </div>
                        </div>
                        <div class="mt-4 grid md:grid-cols-2 gap-4">
                            <div>
                                <h5 class="font-medium mb-2">优点</h5>
                                <ul class="space-y-2">
                                    <li class="pros-cons-item pros">对缓存命中率提升显著</li>
                                    <li class="pros-cons-item pros">适合访问频率稳定的数据</li>
                                </ul>
                            </div>
                            <div>
                                <h5 class="font-medium mb-2">缺点</h5>
                                <ul class="space-y-2">
                                    <li class="pros-cons-item cons">需要在实现上加入频率计数结构，增加了管理复杂度</li>
                                    <li class="pros-cons-item cons">对突发访问模式适应不佳</li>
                                </ul>
                            </div>
                        </div>
                    </div>

                    <!-- More strategies can be added in the same pattern -->
                    
                </div>
            </div>

            <div class="bg-blue-50 p-6 rounded-lg">
                <h3 class="text-xl font-semibold mb-4">3. 选择适合的策略组合</h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h4 class="font-medium mb-2">混合策略的应用</h4>
                        <p>在大多数项目中，单一策略难以覆盖所有场景，因此可以混合多种策略。例如，LRU结合TTL可以在高频访问场景中限制缓存的生存时间，达到平衡内存占用与命中率的效果。</p>
                    </div>
                    <div>
                        <h4 class="font-medium mb-2">动态调整机制</h4>
                        <p>可依据数据访问的实时性或用户访问模式的变化，动态调整缓存策略。通过数据访问模式分析，自动调整缓存的更新频率、存储大小或淘汰规则。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Cache Invalidation Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">缓存失效策略</h2>
            <p class="text-lg mb-6">在分布式系统中设计缓存时，缓存失效策略是关键的一环，直接影响系统的性能、缓存命中率、数据的一致性和资源利用率。</p>
            
            <div class="mb-8">
                <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1730173848056-6b3784b8-8e40-47cf-b2e9-678e849c8a9c.png" alt="缓存失效图" class="w-full rounded-lg shadow-md card">
            </div>

            <div class="grid md:grid-cols-2 gap-6 mb-8">
                <!-- Strategy 1 -->
                <div class="bg-white p-6 rounded-lg shadow-sm card">
                    <div class="flex items-start mb-4">
                        <div class="bg-blue-500 text-white rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0 mr-3">1</div>
                        <div>
                            <h3 class="font-semibold text-lg">定时失效（Time-based Expiration）</h3>
                        </div>
                    </div>
                    <div class="pl-11">
                        <p class="mb-3"><strong>策略概述：</strong>通过为缓存中的每条数据设置一个生命周期（TTL，Time-to-Live），在超过指定时间后数据即自动失效。</p>
                        <p class="mb-2"><strong>应用场景：</strong>适用于对数据的时效性要求较高的场景，如推荐系统、新闻资讯等短周期数据缓存。</p>
                        <div class="grid md:grid-cols-2 gap-4 mt-3">
                            <div class="bg-green-50 p-3 rounded">
                                <h4 class="font-medium text-green-700 mb-1">优点</h4>
                                <p class="text-sm">操作简便，能自动清除过期数据，保证数据的时效性。</p>
                            </div>
                            <div class="bg-red-50 p-3 rounded">
                                <h4 class="font-medium text-red-700 mb-1">缺点</h4>
                                <p class="text-sm">过期时间设置不当会导致缓存命中率低或缓存击穿。</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Strategy 2 -->
                <div class="bg-white p-6 rounded-lg shadow-sm card">
                    <div class="flex items-start mb-4">
                        <div class="bg-blue-500 text-white rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0 mr-3">2</div>
                        <div>
                            <h3 class="font-semibold text-lg">主动失效（Active Expiration）</h3>
                        </div>
                    </div>
                    <div class="pl-11">
                        <p class="mb-3"><strong>策略概述：</strong>缓存系统与数据源保持关联，一旦数据源更新或删除时，主动将相关缓存数据清除。</p>
                        <p class="mb-2"><strong>应用场景：</strong>适用于数据频繁更新的场景，如电商库存、用户个人信息等。</p>
                        <div class="grid md:grid-cols-2 gap-4 mt-3">
                            <div class="bg-green-50 p-3 rounded">
                                <h4 class="font-medium text-green-700 mb-1">优点</h4>
                                <p class="text-sm">能够有效避免缓存脏数据，提高缓存和数据库的一致性。</p>
                            </div>
                            <div class="bg-red-50 p-3 rounded">
                                <h4 class="font-medium text-red-700 mb-1">缺点</h4>
                                <p class="text-sm">需要额外的实现逻辑和通知机制，复杂度较高。</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- More strategies can be added in the same pattern -->
                
            </div>

            <!-- Visualization -->
            <div class="mermaid">
                flowchart LR
                    A[数据更新] --> B{失效策略}
                    B -->|定时失效| C[TTL过期自动清除]
                    B -->|主动失效| D[立即清除相关缓存]
                    B -->|被动失效| E[访问时检查并更新]
                    B -->|定期清理| F[批量清理过期数据]
            </div>
        </section>

        <!-- Cache Protection Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">缓存穿透、雪崩、击穿防护</h2>
            
            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <!-- Penetration -->
                <div class="bg-white p-6 rounded-lg shadow-md card">
                    <div class="text-center mb-4">
                        <div class="w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-3">
                            <i class="fas fa-shield-alt text-red-500 text-2xl"></i>
                        </div>
                        <h3 class="font-semibold text-xl">缓存穿透</h3>
                    </div>
                    <p class="mb-4 text-sm">对数据库中不存在的数据请求，因缓存没有命中而直接穿透到数据库。恶意请求不断访问不存在的数据，给数据库带来巨大负担。</p>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span class="text-sm">布隆过滤器拦截不存在的数据</span>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span class="text-sm">空值缓存短TTL</span>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span class="text-sm">参数校验与限流</span>
                        </div>
                    </div>
                </div>

                <!-- Avalanche -->
                <div class="bg-white p-6 rounded-lg shadow-md card">
                    <div class="text-center mb-4">
                        <div class="w-16 h-16 bg-yellow-100 rounded-full flex items-center justify-center mx-auto mb-3">
                            <i class="fas fa-exclamation-triangle text-yellow-500 text-2xl"></i>
                        </div>
                        <h3 class="font-semibold text-xl">缓存雪崩</h3>
                    </div>
                    <p class="mb-4 text-sm">缓存系统在短时间内大量失效，导致请求直接落到数据库层。通常发生在大量缓存设置相同过期时间的情况下。</p>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span class="text-sm">缓存过期时间分散</span>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span class="text-sm">限流降级机制</span>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span class="text-sm">多级缓存设计</span>
                        </div>
                    </div>
                </div>

                <!-- Breakdown -->
                <div class="bg-white p-6 rounded-lg shadow-md card">
                    <div class="text-center mb-4">
                        <div class="w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mx-auto mb-3">
                            <i class="fas fa-bolt text-blue-500 text-2xl"></i>
                        </div>
                        <h3 class="font-semibold text-xl">缓存击穿</h3>
                    </div>
                    <p class="mb-4 text-sm">缓存中存在一个热点数据，大量并发请求同时访问，当缓存失效后，瞬间的大量请求穿透到数据库，可能导致数据库负载激增。</p>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span class="text-sm">互斥锁(Mutex)机制</span>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span class="text-sm">"永不过期"策略</span>
                        </div>
                        <div class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span class="text-sm">分布式锁</span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="mermaid">
                flowchart TD
                    A[缓存问题] --> B[缓存穿透]
                    A --> C[缓存雪崩]
                    A --> D[缓存击穿]
                    B --> E[布隆过滤器]
                    B --> F[空值缓存]
                    B --> G[参数校验]
                    C --> H[分散TTL]
                    C --> I[多级缓存]
                    C --> J[限流降级]
                    D --> K[互斥锁]
                    D --> L[热数据不失效]
                    D --> M[分布式锁]
            </div>
        </section>

        <!-- Cache Monitoring Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">缓存监控与优化</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-2xl font-semibold mb-4">1. 缓存监控</h3>
                    <div class="space-y-6">
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-medium mb-3 flex items-center">
                                <i class="fas fa-chart-line text-blue-500 mr-2"></i>
                                缓存命中率和失效率
                            </h4>
                            <p>缓存命中率是缓存系统中请求直接从缓存返回的比例，是反映缓存效果的核心指标。高命中率意味着大多数请求都能在缓存中找到数据，从而减轻数据库压力。</p>
                        </div>
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-medium mb-3 flex items-center">
                                <i class="fas fa-tachometer-alt text-blue-500 mr-2"></i>
                                请求量监控
                            </h4>
                            <p>对缓存请求的流量变化进行实时监控，尤其关注高峰期的请求量变化。突增的请求量可能是因缓存雪崩导致的直接访问数据库，应及时调整缓存以降低数据库压力。</p>
                        </div>
                    </div>
                </div>
                <div>
                    <h3 class="text-2xl font-semibold mb-4">2. 缓存优化策略</h3>
                    <div class="space-y-6">
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-medium mb-3 flex items-center">
                                <i class="fas fa-sliders-h text-blue-500 mr-2"></i>
                                调整缓存策略
                            </h4>
                            <p>根据业务需求选择合适的缓存淘汰算法，如LRU（最近最少使用）、LFU（最少使用）、FIFO（先进先出）等，确保内存使用率与缓存效果达到平衡。</p>
                        </div>
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-medium mb-3 flex items-center">
                                <i class="fas fa-fire text-blue-500 mr-2"></i>
                                热点数据优化
                            </h4>
                            <p>识别并单独管理热点数据，通过增加缓存层级、设定较长的TTL或利用内存优先级等方式，避免热点数据频繁更新和删除，提升系统稳定性。</p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="bg-blue-50 p-6 rounded-lg">
                <h3 class="text-xl font-semibold mb-4">监控指标仪表板示例</h3>
                <div class="grid md:grid-cols-4 gap-4 text-center">
                    <div class="bg-white p-4 rounded-lg">
                        <div class="text-3xl font-bold text-blue-600 mb-1">98.7%</div>
                        <div class="text-sm text-gray-600">命中率</div>
                    </div>
                    <div class="bg-white p-4 rounded-lg">
                        <div class="text-3xl font-bold text-blue-600 mb-1">1.3%</div>
                        <div class="text-sm text-gray-600">失效率</div>
                    </div>
                    <div class="bg-white p-4 rounded-lg">
                        <div class="text-3xl font-bold text-blue-600 mb-1">24.5K</div>
                        <div class="text-sm text-gray-600">QPS</div>
                    </div>
                    <div class="bg-white p-4 rounded-lg">
                        <div class="text-3xl font-bold text-blue-600 mb-1">3ms</div>
                        <div class="text-sm text-gray-600">平均延迟</div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Cache Selection Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">缓存选择与持久化</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-2xl font-semibold mb-4">1. 缓存系统的选择</h3>
                    <div class="space-y-6">
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-medium mb-3 flex items-center">
                                <i class="fas fa-memory text-blue-500 mr-2"></i>
                                本地缓存 (In-Memory Cache)
                            </h4>
                            <p>适用于单节点或轻量级缓存需求，数据存储在应用服务器的内存中，如Guava、Caffeine等。优点是访问速度极快，延迟极低，适合频繁访问的小数据集。</p>
                        </div>
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-medium mb-3 flex items-center">
                                <i class="fas fa-network-wired text-blue-500 mr-2"></i>
                                分布式缓存
                            </h4>
                            <p>如Redis、Memcached等，适合集群环境，数据存储在独立的缓存服务器中。分布式缓存支持多节点共享，并能够根据需求进行水平扩展，适合高并发、低延迟的数据需求。</p>
                        </div>
                    </div>
                </div>
                <div>
                    <h3 class="text-2xl font-semibold mb-4">2. 缓存持久化策略</h3>
                    <div class="space-y-6">
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-medium mb-3 flex items-center">
                                <i class="fas fa-camera text-blue-500 mr-2"></i>
                                RDB快照持久化
                            </h4>
                            <p>RDB方式会在指定的时间间隔创建Redis内存中的数据快照，保存到磁盘。RDB持久化优点在于存储文件小、恢复速度快，适合不需要高实时性的缓存数据。</p>
                        </div>
                        <div class="bg-white p-5 rounded-lg shadow-sm">
                            <h4 class="font-medium mb-3 flex items-center">
                                <i class="fas fa-scroll text-blue-500 mr-2"></i>
                                AOF日志持久化
                            </h4>
                            <p>AOF持久化会记录每条写操作，并将其追加到日志文件中，能够保证数据的高度一致性。AOF具有"每秒同步"、"每次写入"和"不同步"等几种模式。</p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="mermaid">
                pie title 缓存系统选择标准
                    "性能" : 35
                    "数据结构支持" : 20
                    "可扩展性" : 25
                    "持久化能力" : 20
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8 px-4">
        <div class="container mx-auto max-w-6xl">
            <div class="flex flex-col items-center footer-line">
                <div class="mb-4">
                    <h3 class="text-xl font-semibold text-white">技术小馆</h3>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="hover:text-white transition-colors">
                        <i class="fas fa-link mr-2"></i>
                        http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            pie: {
                useWidth: 900,
                showLabels: true,
                textPosition: 0.8
            }
        });
        
        // Add tooltip functionality
        document.querySelectorAll('.tooltip-icon').forEach(el => {
            const title = el.getAttribute('title');
            if (title) {
                el.removeAttribute('title');
                
                const tooltip = document.createElement('div');
                tooltip.className = 'hidden bg-gray-800 text-white text-xs rounded p-2 absolute z-10';
                tooltip.textContent = title;
                document.body.appendChild(tooltip);
                
                const updatePosition = () => {
                    const rect = el.getBoundingClientRect();
                    tooltip.style.left = `${rect.right + window.scrollX + 5}px`;
                    tooltip.style.top = `${rect.top + window.scrollY}px`;
                };
                
                el.addEventListener('mouseenter', () => {
                    tooltip.classList.remove('hidden');
                    updatePosition();
                });
                
                el.addEventListener('mouseleave', () => {
                    tooltip.classList.add('hidden');
                });
                
                window.addEventListener('scroll', () => {
                    if (!tooltip.classList.contains('hidden')) {
                        updatePosition();
                    }
                });
            }
        });
    </script>
</body>
</html>
```